<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{path: '/merchant-home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区 -->
    <el-card class="box-card">
      <!-- 搜索与添加区域 -->
      <el-row :gutter="30">
        <el-col :span="9">
          <el-input
            placeholder="请输入名字"
            v-model="queryInfo.query"
            clearable
            @clear="getMenberlist"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getMenberlist"
            ></el-button>
          </el-input>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" @click="addDialogVisible = true">添加会员</el-button>
        </el-col>
      </el-row>
    </el-card>
    <!-- 员工列表 -->
    <el-table :data="menberlist" border stripe>
      <el-table-column type="index" label="#"></el-table-column>
      <el-table-column prop="nickname" label="昵称"></el-table-column>
      <el-table-column prop="name" label="姓名"></el-table-column>
      <el-table-column prop="password" label="密码"></el-table-column>
      <el-table-column prop="gender" label="性别"></el-table-column>
      <el-table-column prop="headportrait" label="头像"></el-table-column>
      <el-table-column prop="telephone" label="联系电话"></el-table-column>
      <el-table-column prop="addtime" label="创建时间"></el-table-column>
      <el-table-column label="操作" width="180px">
        <template slot-scope="scope">
          <!-- 修改按钮 -->
          <el-button type="primary" icon="el-icon-edit" size="mini" @click="showEditDialog(scope.row.id)"></el-button>
          <!-- 删除按钮 -->
          <el-button
            type="danger"
            icon="el-icon-delete"
            size="mini"
            @click="removeMemberById(scope.row.id)"
          ></el-button>
        </template>
      </el-table-column>
      <!-- <el-table-column label="状态">
        <template slot-scope="scope">
          {{ scope.row }}
        </template>
      </el-table-column> -->
    </el-table>
    <!-- 分页 -->
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        >
    </el-pagination>
    <!-- 添加员工的对话框 -->
    <el-dialog
      title="添加会员"
      :visible.sync="addDialogVisible"
      width="50%"
      @close="addDialogClosed"
    >
    <!-- 内容主体区 -->
    <el-form :model="addForm" :rules="addFormRules" ref="addFormRef" label-width="90px">
      <el-form-item label="昵称" prop="nickname">
        <el-input v-model="addForm.nickname"></el-input>
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input v-model="addForm.name"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="addForm.password"></el-input>
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-radio-group v-model="addForm.gender">
            <el-radio label="男"></el-radio>
            <el-radio label="女"></el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="头像" prop="headportrait">
        <el-input v-model="addForm.headportrait"></el-input>
      </el-form-item>
      <el-form-item label="电话" prop="telephone">
        <el-input v-model="addForm.telephone"></el-input>
      </el-form-item>
    </el-form>
      <!-- 底部区域 -->
      <span slot="footer" class="dialog-footer">
        <el-button @click="addDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="addMember">确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 修改员工的对话框 -->
    <el-dialog
      title="修改用户"
      :visible.sync="editDialogVisible"
      width="50%" @close="editDialogClosed">
      <el-form :model="editForm" :rules="editFormRules" ref="editFormRef" label-width="90px">
        <el-form-item label="昵称" prop="nickname">
          <el-input v-model="editForm.nickname"></el-input>
        </el-form-item>
        <el-form-item label="姓名" >
          <el-input v-model="editForm.name" disabled></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="editForm.password"></el-input>
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-radio-group v-model="editForm.gender">
              <el-radio label="男"></el-radio>
              <el-radio label="女"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="头像" prop="headportrait">
          <el-input v-model="editForm.headportrait"></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="telephone">
          <el-input v-model="editForm.telephone"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editMemberInfo">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
    data() {
        return {
            queryInfo: {
                query: '',
                pagenum: 1,
                pagesize: 2
            },
            menberlist: {},
            total: 0,
            addDialogVisible: false,
            addForm: {
                nickname: '',
                name: '',
                password: '',
                gender: '',
                headportrait: '',
                telephone: ''
            },
            // 添加表单的验证规则对象
            addFormRules: {
              nickname: [{ required: true, message: '请输入用户名', trigger: 'blur' },
                        { min: 3, max: 10, message: '用户名的长度在3~10个字符之间', teigger: 'blur' }],
              name: [{ required: true, message: '请输入用户名', trigger: 'blur' },
                    { min: 3, max: 10, message: '用户名的长度在3~10个字符之间', teigger: 'blur' }],
              password: [{ required: true, message: '请输入密码', trigger: 'blur' },
                        { min: 6, max: 15, message: '密码的长度在6~15个字符之间', teigger: 'blur' }],
              gender: [{ required: true, message: '请选择性别', trigger: 'blur' }],
              headportrait: [{ required: false, message: '请上传头像' }],
              telephone: [{ required: true, message: '请输入联系电话', trigger: 'blur' },
                          { pattern: /^1[3456789]\d{9}$/, message: '请输入正确的联系电话', trigger: 'blur' }]
            },
            editDialogVisible: false,
            editForm: {},
            editFormRules: {
                nickname: [{ required: true, message: '请输入用户名', trigger: 'blur' },
                           { min: 3, max: 10, message: '用户名的长度在3~10个字符之间', teigger: 'blur' }],
                name: [{ required: true, message: '请输入用户名', trigger: 'blur' },
                       { min: 3, max: 10, message: '用户名的长度在3~10个字符之间', teigger: 'blur' }],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' },
                           { min: 6, max: 15, message: '密码的长度在6~15个字符之间', teigger: 'blur' }],
                gender: [{ required: true, message: '请选择性别', trigger: 'blur' }],
                headportrait: [{ required: false, message: '请上传头像' }],
                telephone: [{ required: true, message: '联系电话不能为空' },
                           { min: 11, max: 11, message: '联系电话为11字符', teigger: 'blur' }]
            }
        }
    },
    created() {
        this.getMenberlist()
    },
    methods: {
        async getMenberlist() {},
        // 监听 pagesize 改变的事件
        handleSizeChange(newSize) {
            this.queryInfo.pagesize = newSize
            this.getMenberlist()
            console.log(newSize)
        },
        // 监听页码值改变的事件
        handleCurrentChange(newPage) {
            this.queryInfo.pagenum = newPage
            this.getMenberlist()
        },
        // 监听修改会员对话框的关闭事件
        editDialogClosed() {
            this.$refs.editFormRef.resetFields()
        },
        // 监听添加会员对话框的关闭事件
        addDialogClosed() {
        this.$refs.addFormRef.resetFields()
        },
        // 添加会员事件
        addMember() {
        },
        // 删除会员按钮事件
        async removeMemberById(id) {
        },
        async showEditDialog(id) {},
        // 修改用户事件
        editMemberInfo() {}
    }
}
</script>

<style>

</style>
